<script setup lang="ts">
import './node-style.scss'
import {inject, ref} from "vue";
import {Node} from "@antv/x6";

const formData = reactive<any>({
  strategy:undefined,
  keyPath:undefined,
})
const id=ref<string>()
const getNode=inject<()=>Node>('getNode')
if(getNode){
  const node=getNode()
  id.value=node.id
  node.setData(formData)
}
onBeforeMount(()=>{
  if(getNode){
    const node=getNode()
    const d=node.getData()
    if (d){
      Object.assign(formData,d)
    }else {
      node.setData(formData)
    }
  }
})
watch(formData,()=>{
  if(getNode){
    const node=getNode()
    node.setData(formData)
  }
},{deep:true,immediate:false})
</script>

<template>
  <div class="node">
    <div class="line5 node-title">
      <div class="flow-dot" magnet="true" :class="'flow-exec'" x-type="input-exec" :x-id="'input-exec_'+id"></div>
      <div>文档转换</div>
      <div class="flow-dot flow-right flow-exec" magnet="true" x-type="output-exec" :x-id="'output-exec_'+id"></div>
    </div>
    <div class="line5">
      <div class="flow-dot flow-array-document" magnet="true" x-type="input-array-document" :x-id="'input-array-document_'+id"></div>
      <div>文档集合</div>
    </div>
    <div class="line5">
      <div class="flow-right">文本集合</div>
      <div class="flow-dot flow-array-string" magnet="true" x-type="output-array-string" :x-id="'output-array-string_'+id" x-key="array_string"></div>
    </div>
    <el-form
      :model="formData"
      label-position="top"
      @mousedown.stop
      @focus.stop
      style="cursor: default">
      <el-form-item label="提取策略">
        <el-select v-model="formData.strategy" placeholder="选择提取策略">
          <el-option label="提取文档内容" value="content"/>
          <el-option label="提取元数据" value="meta"/>
        </el-select>
      </el-form-item>
      <el-form-item label="键名" v-if="formData.strategy==='meta'">
        <el-input v-model="formData.keyPath" placeholder="key path"/>
        <el-alert title="如{'user':{'name':'xxx'}};key path为user.name"/>
      </el-form-item>
    </el-form>
  </div>
</template>

<style scoped lang="scss">

</style>
